<?php
namespace wechat\controllers;

use Yii;
use yii\base\Event;
use yii\helpers\Url;
use yii\base\Exception;
use yii\web\Controller;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use framework\helpers\Utils;
/**
 * Site controller
 */
class SiteController extends Controller
{
	public $layout = 'layout';
	
	public function actionIndex()
	{
		return $this->redirect(['site/main']);
	}
	
	//注册发送验证码
	public function actionSendcode()
	{
		if (yii::$app->request->post('name') && yii::$app->request->post('phone'))
		{
			$name = yii::$app->request->post('name');  //用户名
			$phone = yii::$app->request->post('phone'); //手机号
			$url = Utils::encrypt(PANDA_SERVER.'/sendMsgCodeRegister?username='.$name.'&phone='.$phone.'&tokenId='.Utils::getTokenId());  //获取验证码的接口URL
			$result = file_get_contents($url);
			$json = Utils::TOGATE($result);	//验签解签操作
			echo $json;
			exit;
		}
	}
	//找回登录密码发送验证码
	public function actionSendlogincode()
	{
		if (yii::$app->request->post('name') && yii::$app->request->post('phone'))
		{
			$name = yii::$app->request->post('name');  //用户名
			$phone = yii::$app->request->post('phone'); //手机号
			$url = Utils::encrypt(PANDA_SERVER.'/sendMsgCodeLogin?username='.$name.'&phone='.$phone.'&tokenId='.Utils::getTokenId());  //获取验证码的接口URL
			$result = file_get_contents($url);
			$json = Utils::TOGATE($result);	//验签解签操作
			echo $json;
			exit;
		}
	}
	//找回投资密码发送验证码
	public function actionSendinvestcode()
	{
		$session = yii::$app->session;
		$session->open();
		if($session->has('sKey'))	//是否有sKey缓存
		{
			$sKey = $session->get('sKey');
			$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());
			$result = file_get_contents($url);
			$json = Utils::TOGATE($result);	//验签解签操作
			$result_arr = json_decode($json,true); // JSON结果字符串转数组
			if ($result_arr['status']!=0)	//sKey过期
			{
				echo 'sKey无效！';
			}
			else 	//已登录
			{
				if(yii::$app->request->post('phone'))
				{
					$phone = yii::$app->request->post('phone'); //手机号
					$_url = Utils::encrypt(PANDA_SERVER.'/sendMsgCodeInvest?sKey='.$sKey.'&tokenId='.Utils::getTokenId());  //找回投资密码功能的发送短信验证码操作。
					$_result = file_get_contents($_url);
					$json1 = Utils::TOGATE($_result);	//验签解签操作
					echo $json1;
					exit;
				}
			}
		}
		else
		{
			echo 'sKey无效！';
		}
	}
	public function actionError()
	{
		return $this->render('error');
	}
	public function actionMain()
	{
		Utils::ensureOpenId();
		$Banners = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/queryBannerPicsList?order=0&tokenId='.Utils::getTokenId())));
		$Banners = json_decode($Banners,true);
		$BidList = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/queryHomeBidList?order=0&curr=1&num=7&tokenId='.Utils::getTokenId())));
		$BidList = json_decode($BidList,true)['list'];
		$RepayList = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/queryHomeRepayList?order=0&curr=1&num=7&tokenId='.Utils::getTokenId())));
		$RepayList = json_decode($RepayList,true)['list'];
		$FinishList = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/queryHomeFinishList?order=0&curr=1&num=7&tokenId='.Utils::getTokenId())));
		$FinishList = json_decode($FinishList,true)['list'];
		return $this->render('main',compact('BidList','RepayList','FinishList','Banners'));
	}
	//还款中慢加载列表
	public function actionRepaylist()
	{
	if($_REQUEST)
        {
            $page = intval($_REQUEST['page']);
            $page_num = intval($_REQUEST['num']);
            $result = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/queryHomeRepayList?order=0&curr='.$page.'&num='.$page_num.'&tokenId='.Utils::getTokenId())));
            //$datas = json_encode($result[data][data]);
			echo $result;
        }
	}
	//已完成慢加载列表
	public function actionFinishlist()
	{
		if($_REQUEST)
		{
			$page = intval($_REQUEST['page']);
			$page_num = intval($_REQUEST['num']);
			$result = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/queryHomeFinishList?order=0&curr='.$page.'&num='.$page_num.'&tokenId='.Utils::getTokenId())));
			//$datas = json_encode($result[data][data]);
			echo $result;
		}
	}
	//竞标中慢加载列表
	public function actionBidlist()
	{
		if($_REQUEST)
		{
			$page = intval($_REQUEST['page']);
			$page_num = intval($_REQUEST['num']);
			$result = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/queryHomeBidList?order=0&curr='.$page.'&num='.$page_num.'&tokenId='.Utils::getTokenId())));
			//$datas = json_encode($result[data][data]);
			echo $result;
		}
	}
	//项目详情
	public  function actionDetail($id)
	{
		$infos = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/getInvestInfo?id='.$id.'&tokenId='.Utils::getTokenId())));
		$infos = json_decode($infos,true)["obj"];
		return $this->render('detail',compact('infos'));
	}
	//项目详情-产品资料
	public  function actionInformation($id)
	{
		//获取某个标的项目公证文件图片
		$infos = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/getInvestInfo?id='.$id.'&tokenId='.Utils::getTokenId())));
		$infos = json_decode($infos,true)["obj"]['pics'];
		return $this->render('information',compact('infos','id'));
	}
	//投资记录慢加载列表
	public function actionInvestlist($id)
	{
		if($_REQUEST)
		{
			$page = intval($_REQUEST['page']);
			$page_num = intval($_REQUEST['num']);
			$result = Utils::TOGATE(file_get_contents(Utils::encrypt(PANDA_SERVER.'/queryInvestList?order=0&curr='.$page.'&num='.$page_num.'&id='.$id.'&tokenId='.Utils::getTokenId())));
			//$datas = json_encode($result[data][data]);
			echo $result;
		}
	}
	//个人账户
	public  function actionAccountself()
	{
		$session = yii::$app->session;
		$session->open();
		if($session->has('sKey'))	//是否有sKey缓存
		{
			$sKey = $session->get('sKey');
			$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());
			$result = file_get_contents($url);
			$json = Utils::TOGATE($result);	//验签解签操作
			$result_arr = json_decode($json,true); // JSON结果字符串转数组
			if ($result_arr['status']==61)	//tokenId过期
			{
				Utils::resetTokenid();
				$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());
				$result = file_get_contents($url);
				$json = Utils::TOGATE($result);	//验签解签操作
				$result_arr = json_decode($json,true); // JSON结果字符串转数组
				if ($result_arr['status']==10)	//tokenId过期
				{
					return $this->redirect(['site/signin']);
				}
				elseif ($result_arr['status']==0) 	//已登录
				{
					$url =Utils::encrypt( PANDA_SERVER.'/getUserInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());	//获取登录用户的账户概要信息
					$url1 = Utils::encrypt(PANDA_SERVER.'/queryUserMoneyList?sKey='.$sKey.'&order=0&curr=1&num=7&tokenId='.Utils::getTokenId());	//获取登录用户的资金变动日志。
					$_result = file_get_contents($url);
					$_result1 = file_get_contents($url1);
					$json1 = Utils::TOGATE($_result);	//验签解签操作
					$json2 = Utils::TOGATE($_result1);	//验签解签操作
					$_result_arr = json_decode($json1,true); // JSON结果字符串转数组
					$_result_arr1 = json_decode($json2,true); // JSON结果字符串转数组
					if ($_result_arr['status'] == 0)	//判断是否返回了正常的记录列表
					{
						$userinfos = $_result_arr['obj'];
					}
					else
					{
						$userinfos = null;
					}
					///////////////////////分割线/////////////////////////////////
					if ($_result_arr1['status'] == 0)	//判断是否返回了正常的记录列表
					{
						$moneylist = $_result_arr1['list'];
					}
					else
					{
						$moneylist = null;
					}
				
					return $this->render('accountself',compact('userinfos','moneylist','sKey'));
				}
			}
			elseif ($result_arr['status']==10 || $result_arr['status']==46)	//sKey过期
			{
				return $this->redirect(['site/signin']);
			}
			elseif ($result_arr['status']==0) 	//已登录
			{
				$url =Utils::encrypt( PANDA_SERVER.'/getUserInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());	//获取登录用户的账户概要信息
				$url1 = Utils::encrypt(PANDA_SERVER.'/queryUserMoneyList?sKey='.$sKey.'&order=0&curr=1&num=7&tokenId='.Utils::getTokenId());	//获取登录用户的资金变动日志。
				$_result = file_get_contents($url);
				$_result1 = file_get_contents($url1);
				$json1 = Utils::TOGATE($_result);	//验签解签操作
				$json2 = Utils::TOGATE($_result1);	//验签解签操作
				$_result_arr = json_decode($json1,true); // JSON结果字符串转数组
				$_result_arr1 = json_decode($json2,true); // JSON结果字符串转数组
				if ($_result_arr['status'] == 0)	//判断是否返回了正常的记录列表
				{
					$userinfos = $_result_arr['obj'];
				}
				else
				{
					$userinfos = null;
				}
				///////////////////////分割线/////////////////////////////////
				if ($_result_arr1['status'] == 0)	//判断是否返回了正常的记录列表
				{
					$moneylist = $_result_arr1['list'];
				}
				else
				{
					$moneylist = null;
				}
		
				return $this->render('accountself',compact('userinfos','moneylist','sKey'));
			}
			else 
			{
				return $this->redirect(['site/signin']);
			}
		}
		else
		{
			return $this->redirect(['site/signin']);
		}
	}
	//投资详情
	public  function actionAccountdetail()
	{
		$session = yii::$app->session;
		$session->open();
		if($session->has('sKey'))	//是否有sKey缓存
		{
			$sKey = $session->get('sKey');
			$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());
			$result = file_get_contents($url);
			$json = Utils::TOGATE($_result);	//验签解签操作
			$result_arr = json_decode($json,true); // JSON结果字符串转数组
			if ($result_arr['status']==61)	//tokenId过期
			{
				Utils::resetTokenid();
				$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());
				$result = file_get_contents($url);
				$json = Utils::TOGATE($result);	//验签解签操作
				$result_arr = json_decode($json,true); // JSON结果字符串转数组
				if ($result_arr['status']==10)	//tokenId过期
				{
					return $this->redirect(['site/signin']);
				}
				else 
				{
					$url = Utils::encrypt(PANDA_SERVER.'/getUserUncollected?sKey='.$sKey.'&tokenId='.Utils::getTokenId());	//获取登录用户的账户概要信息
					$url1 = Utils::encrypt(PANDA_SERVER.'/queryUncollectedBidList?sKey='.$sKey.'&order=0&curr=1&num=7&tokenId='.Utils::getTokenId());	//获取登录用户已投资且仍在竞投中的标。
					$_result = file_get_contents($url);
					$_result1 = file_get_contents($url1);
					$json1 = Utils::TOGATE($_result);	//验签解签操作
					$json2 = Utils::TOGATE($_result1);	//验签解签操作
					$_result_arr = json_decode($json1,true); // JSON结果字符串转数组
					$_result_arr1 = json_decode($json2,true); // JSON结果字符串转数组
					if ($_result_arr['status'] == 0)	//判断是否返回了正常的记录列表
					{
						$userinfos = $_result_arr['obj'];
					}
					else
					{
						$userinfos = null;
					}
					///////////////////////分割线/////////////////////////////////
					if ($_result_arr1['status'] == 0)	//判断是否返回了正常的记录列表
					{
						$bidlist = $_result_arr1['list'];
					}
					else
					{
						$bidlist = null;
					}
					return $this->render('accountdetail',compact('userinfos','bidlist','sKey'));
				}
			}
			elseif ($result_arr['status']==61)	//tokenId过期
			{
				return $this->redirect(['site/signin']);
			}
			else 	//已登录
			{
				$url = Utils::encrypt(PANDA_SERVER.'/getUserUncollected?sKey='.$sKey.'&tokenId='.Utils::getTokenId());	//获取登录用户的账户概要信息
				$url1 = Utils::encrypt(PANDA_SERVER.'/queryUncollectedBidList?sKey='.$sKey.'&order=0&curr=1&num=7&tokenId='.Utils::getTokenId());	//获取登录用户已投资且仍在竞投中的标。
				$_result = file_get_contents($url);
				$_result1 = file_get_contents($url1);
				$json1 = Utils::TOGATE($_result);	//验签解签操作
				$json2 = Utils::TOGATE($_result1);	//验签解签操作
				$_result_arr = json_decode($json1,true); // JSON结果字符串转数组
				$_result_arr1 = json_decode($json2,true); // JSON结果字符串转数组
				if ($_result_arr['status'] == 0)	//判断是否返回了正常的记录列表
				{
					$userinfos = $_result_arr['obj'];
				}
				else
				{
					$userinfos = null;
				}
				///////////////////////分割线/////////////////////////////////
				if ($_result_arr1['status'] == 0)	//判断是否返回了正常的记录列表
				{
					$bidlist = $_result_arr1['list'];
				}
				else
				{
					$bidlist = null;
				}
				return $this->render('accountdetail',compact('userinfos','bidlist','sKey'));
			}
		}
		else
		{
			return $this->redirect(['site/signin']);
		}
	}
	//充值
	public  function actionRecharge()
	{
		return $this->render('recharge');
	}
	
	public function actionSignin()
	{//var_dump(Utils::getTokenId());exit;
		//var_dump(Utils::decrypt('B4Zr8uw9IIJ2RzoO1h1P97MXUcnKyvw82k5fKPvnq3e/cIDEZ/HnDBP3Zk18OtMT0ROW/qX0/9OCOEbqYHIfzAan4qJb3jWKLQT3eEx7+PK6m4fyXjXifwChBpq1AY2uVNgVPHGCQjH4CszKYfbv7aJAkXT+i9srZvegLy7bNoU='));exit;
		//var_dump(Utils::encrypt('{"msg":"操作成功！","status":0}'));exit;
			//var_dump(Utils::encrypt(PANDA_SERVER.'/login?username=44'.'&pwd=55'.'&tokenId=B2B1F3B04660E2E1EC9CB1C8A8F77FEF'));exit;
		if (yii::$app->request->post('name') && yii::$app->request->post('password'))
		{
			$name = yii::$app->request->post('name');
			$password = yii::$app->request->post('password');
			$encrypt_url = Utils::encrypt(PANDA_SERVER.'/login?username='.$name.'&pwd='.$password.'&tokenId='.Utils::getTokenId());
			$result = file_get_contents($encrypt_url);
			if($result)
			{
				$result = Utils::decrypt($result);
				$result = Utils::_substr($result);
				if (! Utils::vertify_sign($result))
				{
					return false;
				}
				if (json_decode($result[0],true)['status']==0)
				{
					$session = yii::$app->session;
					$session->open();
					$session->set('_USERNAME',$name);
					$session->set('_PASSWORD',$password);
				}
				echo $result[0];
				exit;
			}
			else 
			{
				return '服务器处理异常';
				exit;
			}
		}
		return $this->render('signin');
	}
	
	//清除SESSION
	public  function actionDestroy()
	{
		$session = Yii::$app->session;
		$session->open();
		$session->destroy();
		return $this->redirect(['site/signin']);
	}
	
	public function actionForgotloginpw(){
		return $this->render('forgotloginpw');
	}
	public function actionForgotstep1(){
		$session = Yii::$app->session;
		$session->open();
		if($_POST){
			$session->set('phone', $_POST['phone']);
			$session->set('username', $_POST['name']);
			$session->set('msgcode', $_POST['msgcode']);
			$session->set('imgcode', $_POST['imgcode']);
		}
		return $this->render('forgotstep1');
	}
	public function actionForgotfinish()
	{
		$session = yii::$app->session;
		$session->open();
		if($_POST)
		{
			$pwd = $_POST['password'];
			$qrpwd = $_POST['qrpassword'];
			$username = $session->get('username');
			$phone = $session->get('phone');
			$msgcode = $session->get('msgcode');
			$imgcode = $session->get('imgcode');
			$url = Utils::encrypt(PANDA_SERVER.'/retrieveLoginPwd?username='.$username.'&phone='.$phone.'&CAPTCHA='.$imgcode.'&msgCode='.$msgcode.'&pwd='.$pwd.'&pwdConfirm='.$qrpwd.'&tokenId='.Utils::getTokenId());  //获取短信验证码的接口URL
				//删除SESSION
				$session->set('phone', '');
				$session->set('username', '');
				$session->set('msgcode', '');
				$session->set('imgcode', '');
				
			$result = file_get_contents($url);
			$json = Utils::TOGATE($result);	//验签解签操作
			$result_arr = json_decode($json,true); // JSON结果字符串转数组
			if (isset($result_arr['status']) && $result_arr['status']==0)
			{
				$this->redirect(['site/signin']);
			}
		}
	}
	public function actionForgotinvestpw()
	{
		return $this->render('forgotinvestpw');
	}
	public function actionForgotinveststep1(){
		$session = Yii::$app->session;
		$session->open();
		if($_POST){
			$session->set('phone', $_POST['phone']);
			$session->set('msgcode', $_POST['msgcode']);
		}
		return $this->render('forgotinveststep1');
	}
	public function actionForgotinvestfinish()
	{
		$session = yii::$app->session;
		$session->open();
		if($session->has('sKey'))	//是否有sKey缓存
		{
			$sKey = $session->get('sKey');
			$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());
			$result = file_get_contents($url);
			$json = Utils::TOGATE($result);	//验签解签操作
			$result_arr = json_decode($json,true); // JSON结果字符串转数组
			if ($result_arr['status']!=0)	//sKey过期
			{
				return $this->redirect(['site/signin']);
			}
			else 	//已登录
			{
				if($_POST)
				{
					$pwd = $_POST['password'];
					$qrpwd = $_POST['qrpassword'];
					$phone = $session->get('phone');
					$msgcode = $session->get('msgcode');
					$_url = Utils::encrypt(PANDA_SERVER.'/retrieveInvestPwd?sKey='.$sKey.'&msgCode='.$msgcode.'&pwd='.$pwd.'&pwdConfirm='.$qrpwd.'&tokenId='.Utils::getTokenId());  //当用户忘记自己账户投资密码时，可以用此接口找回
					//删除SESSION
					$session->set('phone', '');
					$session->set('msgcode', '');
			
					$_result = file_get_contents($_url);
					$json = Utils::TOGATE($_result);	//验签解签操作
					$_result_arr = json_decode($json,true); // JSON结果字符串转数组
					if (isset($_result_arr['status']) && $_result_arr['status']==0)
					{
						echo "<script>alert('修改成功！')</script>";
						echo "<script>location.href='".Url::to(['site/main'])."';</script>";
					}
					else 
					{
						echo "<script>alert('".$_result_arr['msg']."');</script>";
						echo "<script>location.href='".Url::to(['site/forgotinvestpw'])."';</script>";
					}
				}
			}
		}
		else
		{
			return $this->redirect(['site/signin']);
		}
	}
	//修改登录密码
	public function actionModifyloginpw()
	{
		if (yii::$app->request->isPost)
		{
			$prepassword = yii::$app->request->post('prepassword');  //原密码
			$password = yii::$app->request->post('password'); //新密码
			$session = yii::$app->session;
			$session->open();
			if($session->has('sKey'))	//是否有sKey缓存
			{
				$sKey = $session->get('sKey');
				$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());
				$result = file_get_contents($url);
				$json = Utils::TOGATE($result);	//验签解签操作
				$result_arr = json_decode($json,true); // JSON结果字符串转数组
				if ($result_arr['status']!=0)	//sKey过期
				{
					echo 'sKey无效！';
					exit;
				}
				else 	//已登录
				{
						$_url = Utils::encrypt(PANDA_SERVER.'/changeLoginPwd?sKey='.$sKey.'&oldPwd='.$prepassword.'&newPwd='.$password.'&confirmPwd='.$password.'&tokenId='.Utils::getTokenId());  //修改用户登录密码
							
						$_result = file_get_contents($_url);
						$json1 = Utils::TOGATE($_result);	//验签解签操作
						$_result_arr = json_decode($json1,true); // JSON结果字符串转数组
						if (isset($_result_arr['status']) && $_result_arr['status']==0)
						{
							echo '登录密码修改成功！';exit;
						}
						else
						{
							echo '登录密码修改失败！';exit;
						}
				}
			}
			else
			{
				echo 'sKey无效！';
				exit;
			}
		}
		return $this->render('modifyloginpw');
	}
	//修改投资密码
	public function actionModifyinvestpw()
	{
		if (yii::$app->request->isPost)
		{
			$prepassword = yii::$app->request->post('prepassword');  //原密码
			$password = yii::$app->request->post('password'); //新密码
			$session = yii::$app->session;
			$session->open();
			if($session->has('sKey'))	//是否有sKey缓存
			{
				$sKey = $session->get('sKey');
				$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());
				$result = file_get_contents($url);
				$json = Utils::TOGATE($result);	//验签解签操作
				$result_arr = json_decode($json,true); // JSON结果字符串转数组
				if ($result_arr['status']!=0)	//sKey过期
				{
					echo 'sKey无效！';
					exit;
				}
				else 	//已登录
				{
					if (yii::$app->request->post('prepassword'))
					{
						$_url = Utils::encrypt(PANDA_SERVER.'/changeInvestPwd?sKey='.$sKey.'&oldPwd='.$prepassword.'&newPwd='.$password.'&confirmPwd='.$password.'&tokenId='.Utils::getTokenId());  //修改用户登录密码
					}
					else
					{
						$_url = Utils::encrypt(PANDA_SERVER.'/changeInvestPwd?sKey='.$sKey.'&newPwd='.$password.'&confirmPwd='.$password.'&tokenId='.Utils::getTokenId());  //修改用户登录密码
					}	
					$_result = file_get_contents($_url);
					$json1 = Utils::TOGATE($_result);	//验签解签操作
					$_result_arr = json_decode($json1,true); // JSON结果字符串转数组
					if (isset($_result_arr['status']) && $_result_arr['status']==0)
					{
						echo '投资密码修改成功！';exit;
					}
					else
					{
						echo '投资密码修改失败！';exit;
					}
				}
			}
			else
			{
				echo 'sKey无效！';
				exit;
			}
		}
		return $this->render('modifyinvestpw');
	}
	//用户注册
	public function actionSignup()
	{
		if (yii::$app->request->isPost)
		{
			$request = yii::$app->request;
			$name = $request->post('name');
			$phone = $request->post('phone');
			$password = $request->post('password');
			$qrpassword = $request->post('qrpassword');
			$imgcode = $request->post('imgcode');
			$msgcode = $request->post('msgcode');
			$url = Utils::encrypt(PANDA_SERVER.'/register?username='.$name.'&phone='.$phone.'&pwd='.$password.'&confirmPwd='.$qrpassword.'&CAPTCHA='.$imgcode.'&msgCode='.$msgcode.'&tokenId='.Utils::getTokenId());  //获取短信验证码的接口URL
			$result = file_get_contents($url);
			$json = Utils::TOGATE($result);	//验签解签操作
			$result_arr = json_decode($json,true); // JSON结果字符串转数组
			var_dump($result);exit;
		}
		return $this->render('signup');
	}
	
	//绑卡
	public function actionBindbank()
	{
		$session = yii::$app->session;
		$session->open();
		if($session->has('sKey'))	//是否有sKey缓存
		{
			$sKey = $session->get('sKey');
			$url = PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId();
			$result = file_get_contents($url);
			$result_arr = json_decode($result,true); // JSON结果字符串转数组
			if ($result_arr['status']!=0)	//sKey过期
			{
				return $this->redirect(['site/signin']);
			}
			else 	//已登录
			{
				if (yii::$app->request->isPost)
				{
					$request = yii::$app->request;
					$provice = $request->post('provice');
					$city = $request->post('city');
					$bankname = $request->post('bankname');
					$bankid = $request->post('bankid');
					$address = $request->post('address');
					$url_save = PANDA_SERVER.'/saveBindingBank?sKey='.$sKey.'&bank='.$bankname.'&account='.$bankid.'&provice='.$provice.'&city='.$city.'&address='.$address.'&tokenId='.Utils::getTokenId();  //获取短信验证码的接口URL
					$result_save = file_get_contents($url_save);
					echo $result_save;exit;
				}
			}
		}
		else
		{
			return $this->redirect(['site/signin']);
		}
		$url1 = PANDA_SERVER.'/queryBankNameList?tokenId='.Utils::getTokenId();
		$result1 = file_get_contents($url1);
		$result1 = json_decode($result1)->list;
		$url_province = PANDA_SERVER.'/queryProvList?tokenId='.Utils::getTokenId();
		$result_province = file_get_contents($url_province);
		$result_province = json_decode($result_province)->list;
		$province_arr = [];
		foreach ($result_province as $K=>$V)
		{
			$province_arr[] = $V->name;
		}
		$province_arr = json_encode($province_arr);
		return $this->render('bindbank',compact('result1','province_arr'));
	}
	
	//账户中心
	public function actionMember(){
		$session = yii::$app->session;
		$session->open();
		if (isset($_REQUEST['sKey']) && $_REQUEST['sKey'])  //登录入口
		{
			$sKey = $_REQUEST['sKey'];
			$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());	//获取用户当前账户安全情况
			$result = file_get_contents($url);
			$result = Utils::decrypt($result);//解密操作
			$result = Utils::_substr($result); //解签 并拆成数组
			if (Utils::vertify_sign($result))	//验签操作
			{
				$result_arr = json_decode($result[0],true); // JSON结果字符串转数组
				if ($result_arr['status']==0)
				{
					$session->set('sKey',$sKey);
					$url =  Utils::encrypt(PANDA_SERVER.'/getUserInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());	//获取登录用户的账户概要信息
					$_result = file_get_contents($url);
					$_result = Utils::decrypt($_result);//解密操作
					$_result = Utils::_substr($_result); //解签 并拆成数组
					if (Utils::vertify_sign($_result))	//验签操作
					{
						$_result_arr = json_decode($_result[0],true); // JSON结果字符串转数组
						$userinfos = $_result_arr['obj'];
						return $this->render('account',compact('userinfos'));
					}
				}
			}
			else
			{
				return $this->redirect(['site/signin']);
			}
		}
		elseif($session->has('sKey'))	//已登录
		{
			$sKey = $session->get('sKey');
			$url = Utils::encrypt(PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());
			$result = file_get_contents($url);
			$result = Utils::decrypt($result);//解密操作
			$result = Utils::_substr($result); //解签 并拆成数组
			if (Utils::vertify_sign($result))	//验签操作
			{
				$result_arr = json_decode($result[0],true); // JSON结果字符串转数组
				if ($result_arr['status']!=0)
				{
					return $this->redirect(['site/signin']);
				}
				elseif ($result_arr['status']==61)
				{
					if ($session->has('_USERNAME') && $session->has('_PASSWORD'))
					{
						$name = $session->get('_USERNAME');
						$password = $session->get('_PASSWORD');
						$encrypt_url = Utils::encrypt(PANDA_SERVER.'/login?username='.$name.'&pwd='.$password.'&tokenId='.Utils::getTokenId());
						$result = file_get_contents($encrypt_url);
						if($result)
						{
							$result = Utils::decrypt($result);
							$result = Utils::_substr($result);
							if (! Utils::vertify_sign($result))
							{
								return false;
							}
							if (json_decode($result[0],true)['status']==0)
							{
								$session->set('sKey',json_decode($result[0],true)['sKey']);
							}
							$url = Utils::encrypt(PANDA_SERVER.'/getUserInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());	//获取登录用户的账户概要信息
							$_result = file_get_contents($url);
							$_result = Utils::decrypt($_result);//解密操作
							$_result = Utils::_substr($_result); //解签 并拆成数组
							if (Utils::vertify_sign($_result))	//验签操作
							{
								$_result_arr = json_decode($_result[0],true); // JSON结果字符串转数组
								$userinfos = $_result_arr['obj'];
								return $this->render('account',compact('userinfos'));
							}
						}
					}
					else 
					{
						return $this->redirect(['site/signin']);
					}
				}
				else 
				{
					$url = Utils::encrypt(PANDA_SERVER.'/getUserInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId());	//获取登录用户的账户概要信息
					$_result = file_get_contents($url);
					$_result = Utils::decrypt($_result);//解密操作
					$_result = Utils::_substr($_result); //解签 并拆成数组
					if (Utils::vertify_sign($_result))	//验签操作
					{
						$_result_arr = json_decode($_result[0],true); // JSON结果字符串转数组
						$userinfos = $_result_arr['obj'];
						return $this->render('account',compact('userinfos'));
					}
				}
			}
		}
		else 
		{
			return $this->redirect(['site/signin']);
		}
		
	}
	
	//退出操作
	public function actionLogout()
	{
		$session = yii::$app->session;
		$session->open();
		$session->destroy();
		return $this->redirect(['site/signin']);
	}
	//个人设置
	public function actionSetting()
	{
		$session = yii::$app->session;
		$session->open();
		if($session->has('sKey'))	//是否有sKey缓存
		{
			$sKey = $session->get('sKey');
			$url = PANDA_SERVER.'/getUserSecurityInfo?sKey='.$sKey.'&tokenId='.Utils::getTokenId();
			$result = file_get_contents($url);
			$result_arr = json_decode($result,true); // JSON结果字符串转数组
			if ($result_arr['status']!=0)	//sKey过期
			{
				return $this->redirect(['site/signin']);
			}
			else 	//已登录
			{
				$userinfos = $result_arr['obj'];
				return $this->render('setting',compact('userinfos'));
			}
		}
		else
		{
			return $this->redirect(['site/signin']);
		}
	}
	public static function gosignin()
	{
		self::redirect(['site/signin']);
	}
}